// pages/mine/address/compileAdd/compileAdd.js
const app = getApp();
const util = require("../../../../utils/util.js");
Page({

  /**
 * 页面的初始数据
 */
  data: {
    region: ['湖北省', '武汉市', '江夏区'],
    name: "",
    cellphone: "",
    address: "",
    addressId: ""
  },

  // 选择省市
  bindRegionChange: function (e) {
    // console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      region: e.detail.value
    })
  },

  // 获取收货人姓名
  shName: function (e) {
    let that = this
    that.setData({
      name: e.detail.value
    })
  },

  // 获取收货人电话
  shPhone: function (e) {
    let that = this
    that.setData({
      cellphone: e.detail.value
    })
  },

  // 获取收货人详细地址
  shDetailAdd: function (e) {
    let that = this
    that.setData({
      address: e.detail.value
    })
  },

  // 点击确认修改
  comfirmMod: function(e) {
    let that = this
    // 发送确认修改地址信息请求
    let comfirmUrl = app.globalData.baseUrl + "weixin/editAddress"
    let data = {
      name: that.data.name,
      cellphone: that.data.cellphone,
      address: that.data.address,
      region: that.data.region,
      addressId: that.data.addressId
    }
    util.requestLoading(comfirmUrl, data, "GET").then(res => {
      // console.log(res)
      wx.navigateBack({
        delta: 1
      })
    })
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    that.setData({
      addressId: options.addressId
    })
    // 获取原地址信息
    let oldAddUrl = app.globalData.baseUrl + "weixin/clickEditAddress"
    let data = {
      addressId: that.data.addressId
    }
    util.requestLoading(oldAddUrl, data, "GET").then(res => {
      // console.log(res)
        that.setData({
          name: res.data.addressList[0].name,
          cellphone: res.data.addressList[0].cellphone,
          address: res.data.addressList[0].address,
          region: res.data.addressList[0].region
        })
    })
  },
})